<template>
<basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               ref="crud"
               v-model="form"
               :permission="permissionList"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               :editBtn="true"
               :page="page"
               :upload-after="uploadAfter"
              :upload-delete="uploadDelete"
               @on-load="onLoad">
               <!-- <template slot="menuLeft">
                 <el-button
                   type="primary"
                   icon="el-icon-position"
                   size="medium"
                   @click="pushSell()"
                   >推送
                 </el-button>
               </template> -->

               <template slot-scope="scope" slot="menu">
                <el-button type="danger"
                     icon="el-icon-delete"
                     size="small"
                     plain
                     @click="Removegoods(scope.row)">刪除</el-button>
                <el-button type="primary"
                     icon="el-icon-edit"
                     size="small"
                     plain
                     @click="Editdta(scope.row)">编辑</el-button>
                <!-- <el-button type="success"
                     icon="el-icon-check"
                     size="small"
                     plain
                     @click="handleEdit(scope.row)">补货</el-button>
                <el-button type="warning"
                     icon="el-icon-coin"
                     size="small"
                     plain
                     @click="updatePrice(scope.row)">修改基本数据</el-button>  -->
               </template>
    </avue-crud>

    <el-dialog class="windowopen" title="补货" :visible.sync="dialogFormVisible">
       <div class="batchCodeBox">
        <el-collapse>
          <el-collapse-item>
            <template slot="title">
              <h4 style="color: #409EFF;">选择批次补货</h4>
            </template>
            <el-collapse>
              <el-collapse-item v-for="(item,index) in this.editBatch" style="padding-top: 7px;">
                <template slot="title">
                  <h4>{{ item.batchCode }}</h4>
                </template>
                <div class="batch">
               <el-form v-model="editBatch[index]">
                <div v-if="editBatch[index].baggedNum>0" class="baggedbox"style="margin-bottom: 10px; padding: 10px;border: 1px solid rgb(204, 204, 204);border-radius: 5px;">
                      <el-row style="border: 1px solid #ccc; padding: 20px;border-radius: 10px;">
                        <el-form-item label="袋装进货单价(元) :">
                            <el-input type="number" placeholder="不填默认以批次的进货价" v-model="editBatch[index].sellbaggedPrice" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
                        </el-form-item>
                        <el-form-item label="上架数量(袋) :">
                            <el-input type="number" placeholder="不添加可为空" v-model="editBatch[index].sellbaggedNum" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
                        </el-form-item>
                        <el-form-item label="袋装单净重量(kg) :">
                            <el-input type="number" placeholder="不填默认以批次的净重量" v-model="editBatch[index].sellbaggedWeight" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
                        </el-form-item>
                    </el-row>
                    <el-row style="border: 1px solid #ccc; padding: 20px;border-radius: 10px;">
                          <el-form-item label="袋装进货单价(元) :">
                              <el-input v-model="editBatch[index].baggedPrice" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item> 
                          <el-form-item label="袋装库存(袋) :">
                              <el-input v-model="editBatch[index].baggedNum" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item>
                          <el-form-item label="袋装单净重量(kg) :">
                              <el-input v-model="editBatch[index].baggedWeight" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item> 
                        </el-row>
                    </div>
                    <div v-if="editBatch[index].cartonNum>0" class="baggedbox"style="padding: 10px;border: 1px solid rgb(204, 204, 204);border-radius: 5px;">
                      <el-row style="border: 1px solid #ccc; padding: 20px;border-radius: 10px;">
                        <el-form-item label="箱装进货单价(元) :">
                            <el-input type="number" v-model="editBatch[index].sellcartonPrice" style="width: 50%;" :min="1" oninput="if(value<0)value=0" placeholder="不填默认以批次的进货价"></el-input>
                        </el-form-item>
                        <el-form-item label="上架数量(箱) :">
                            <el-input type="number" v-model="editBatch[index].sellcartonNum" style="width: 50%;" :min="1" oninput="if(value<0)value=0" placeholder="不添加可为空"></el-input>
                        </el-form-item>
                        <el-form-item label="箱装单净重量(kg) :">
                            <el-input type="number" v-model="editBatch[index].sellcartonWeight" style="width: 50%;" :min="1" oninput="if(value<0)value=0" placeholder="不填默认以批次的净重量"></el-input>
                        </el-form-item>
                    </el-row>
                    <el-row style="border: 1px solid #ccc; padding: 20px;border-radius: 10px;">
                          <el-form-item label="箱装进货单价(元) :">
                              <el-input v-model="editBatch[index].cartonPrice" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item> 
                          <el-form-item label="箱装库存(箱) :">
                              <el-input v-model="editBatch[index].cartonNum" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item>
                          <el-form-item label="箱装单净重量(kg) :">
                              <el-input v-model="editBatch[index].cartonWeight" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item> 
                        </el-row>
                    </div>
                    
                     <el-button type="primary"
                     icon="el-icon-check"
                     size="big"
                     style="margin-top: 10px;"
                     @click="addRestockBatch(index)">确定</el-button>
               </el-form>   
            </div>
              </el-collapse-item>
            </el-collapse>
          </el-collapse-item>
        </el-collapse>
       </div>
        
       <div class="addVageBox">
          <el-collapse>
            <el-collapse-item>
              <template slot="title">
                <h4 style="color: #409EFF;">散货</h4>
              </template>
              <el-form :model="formdata">
            <h3><i class="el-icon-s-fold"></i> <el-checkbox v-model="checked1" border>袋装进货</el-checkbox></h3>
            <el-row style="border: 1px solid #ccc; padding: 20px;border-radius: 10px;">
              <el-form-item label="袋装成本单价(元) :">
                  <el-input v-model="formdata.baggedPrice" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
              </el-form-item>
              <el-form-item label="袋装数量(袋) :">
                  <el-input v-model="formdata.baggedNum" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
              </el-form-item>
              <el-form-item label="袋装单净重量(kg) :">
                  <el-input v-model="formdata.baggedWeight" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
              </el-form-item>
            </el-row>

            <h3><i class="el-icon-s-fold"></i> <el-checkbox v-model="checked2" border>箱装进货</el-checkbox></h3>  
            <el-row style="border: 1px solid #ccc; padding: 20px;border-radius: 10px;" :min="1" oninput="if(value<0)value=0">
              <el-form-item label="箱装成本单价(元) :">
                  <el-input v-model="formdata.cartonPrice" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
              </el-form-item> 
              <el-form-item label="箱装数量(箱) :">
                  <el-input v-model="formdata.cartonNum" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
              </el-form-item>
              <el-form-item label="箱装单净重量(kg) :">
                  <el-input v-model="formdata.cartonWeight" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
              </el-form-item> 
            </el-row>
              <el-form-item label="备注 :" style="margin-top: 20px;">
                <el-input type="textarea" v-model="formdata.remark" style="width: 50%;"></el-input>
              </el-form-item>
              <el-button type="primary"
                     icon="el-icon-check"
                     size="big"
                     @click="addRestock()">确定</el-button>
              </el-form>
            </el-collapse-item>
          </el-collapse>
       </div>  
        
    </el-dialog>

    <el-dialog class="windowopen" title="编辑" :visible.sync="dialogFormVisible2">
        <el-form :model="formdata">
          <div v-for="url in this.editdata.imglist" style="display: inline-block;height:30vh;width: 30%;margin-left: 10px;position: relative;">
            <img :src="url" style="width: 100%;height: 100%;" />
            <i class="el-icon-close closeimg" style="position: absolute;top: 1px;right: 0px;font-size: 30px;color: white;font-weight: bold;" @click="uploadDelete(url)"></i>
          </div>
          <div style="padding: 10px;">
            <h2>{{ this.editdata.vegetables }}</h2>
            <h4 style="color: #409EFF;">添加图片</h4>
            <el-upload
              class="avatar-uploader"
              action=""
              :show-file-list="true"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload"
              :auto-upload="false"
              :file-list="uploadImgs"
              :http-request="uploadSectionFile"
              :on-change="handleAvatarChangeIcon"
              :on-remove="handleRemoveIcon"
              list-type="picture-card">
              <!-- v-for="imgurl in this.uploadImgs" -->
               <div v-if="this.uploadImgs.lenght">
                <img v-for="imgurl in this.uploadImgs" :src="imgurl.img" class="avatar">
               </div>
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
            <el-form-item label="類名(元) :">
                  <el-input v-model="formdata.vegetables" type="text" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
              </el-form-item> 
              <el-form-item label="净重量(kg) :">
                  <el-input v-model="formdata.weight" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
              </el-form-item>
          </div>
          
          <el-button type="primary"
            icon="el-icon-check"
            size="big"
            @click="addimg()">确定</el-button>
        </el-form>
    </el-dialog>

    <el-dialog class="windowopen" title="修改基本数据" :visible.sync="dialogFormVisible3">
      <el-form>
        <el-form-item label="种类 :">
          <el-input v-model="formdata2.vegetables" type="text" style="width: 50%;"></el-input>
          <el-button type="primary" icon="el-icon-edit" circle @click="updateVegeName"></el-button>
        </el-form-item>
        
      </el-form>
      <el-collapse>
        <h3>当前售卖批次:</h3>
          <el-collapse-item v-for="(item,index) in this.editBatch" style="padding-top: 7px;">
                <template slot="title">
                  <h4 style="color: #409EFF;">{{item.batchCode}}</h4>
                </template>
                <div class="containerbox">
                   <el-form v-model="editBatch[index]">
                    <div v-if="editBatch[index].baggedNum>0" class="baggedbox"style="margin-bottom: 10px; padding: 10px;border: 1px solid rgb(204, 204, 204);border-radius: 5px;">
                      <el-row style="border: 1px solid #ccc; padding: 20px;border-radius: 10px;">
                        <el-form-item label="袋装单售价(元) :">
                            <el-input type="number" placeholder="不修改可为空" v-model="editBatch[index].sellbaggedPrice" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
                        </el-form-item>
                        <el-form-item label="上架数量(袋) :">
                            <el-input type="number" placeholder="不修改可为空" v-model="editBatch[index].sellbaggedNum" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
                        </el-form-item>
                        <el-form-item label="售卖袋装单净重量(kg) :">
                            <el-input type="number" placeholder="不修改可为空" v-model="editBatch[index].sellbaggedWeight" style="width: 50%;" :min="1" oninput="if(value<0)value=0"></el-input>
                        </el-form-item>
                    </el-row>
                    <el-row style="border: 1px solid #ccc; padding: 20px;border-radius: 10px;">
                          <el-form-item label="袋装进货单价(元) :">
                              <el-input v-model="editBatch[index].baggedPrice" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item> 
                          <el-form-item label="袋装库存(袋) :">
                              <el-input v-model="editBatch[index].baggedNum" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item>
                          <el-form-item label="袋装单净重量(kg) :">
                              <el-input v-model="editBatch[index].baggedWeight" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item> 
                        </el-row>
                    </div>
                    <div v-if="editBatch[index].cartonNum>0" class="baggedbox"style="padding: 10px;border: 1px solid rgb(204, 204, 204);border-radius: 5px;">
                      <el-row style="border: 1px solid #ccc; padding: 20px;border-radius: 10px;">
                        <el-form-item label="箱装单售价(元) :">
                            <el-input type="number" v-model="editBatch[index].sellcartonPrice" style="width: 50%;" :min="1" oninput="if(value<0)value=0" placeholder="不修改可为空"></el-input>
                        </el-form-item>
                        <el-form-item label="上架数量(箱) :">
                            <el-input type="number" v-model="editBatch[index].sellcartonNum" style="width: 50%;" :min="1" oninput="if(value<0)value=0" placeholder="不修改可为空"></el-input>
                        </el-form-item>
                        <el-form-item label="售卖箱装单净重量(kg) :">
                            <el-input type="number" v-model="editBatch[index].sellcartonWeight" style="width: 50%;" :min="1" oninput="if(value<0)value=0" placeholder="不修改可为空"></el-input>
                        </el-form-item>
                    </el-row>
                    <el-row style="border: 1px solid #ccc; padding: 20px;border-radius: 10px;">
                          <el-form-item label="箱装进货单价(元) :">
                              <el-input v-model="editBatch[index].cartonPrice" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item> 
                          <el-form-item label="箱装库存(箱) :">
                              <el-input v-model="editBatch[index].cartonNum" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item>
                          <el-form-item label="箱装单净重量(kg) :">
                              <el-input v-model="editBatch[index].cartonWeight" type="number" style="width: 50%;" :min="1" oninput="if(value<0)value=0" disabled></el-input>
                          </el-form-item> 
                        </el-row>
                    </div>
                    
                     <el-button type="primary"
                     icon="el-icon-check"
                     size="big"
                     style="margin-top: 10px;"
                     @click="updateVege(index)">确定</el-button>
                   </el-form>
                </div>
          </el-collapse-item>
      </el-collapse>
    </el-dialog>

    <el-dialog class="windowopen" title="推送用户" :visible.sync="dialogFormVisible4">
      <el-form>
      </el-form>
    </el-dialog>
    
  </basic-container>
</template>

<script>
import {getList,addage,addRestock,delimg,uploadImg,removegoods,updatebasicdt,getBatchDetail,updateVege,addRestockBatch,getuserList} from "@/api/system/calssfl";
import {getStore} from '@/util/store'

export default{
   data(){
      return{
        data:[],
        checked1:false,
        checked2:false,
        checked3:false,
        checked4:false,
        userlist:[],
        pushdata:[],
        userId:getStore({name: 'userInfo'}).userId,
        roleId:getStore({name: 'userInfo'}).roleId,
        editBatch:[],
        editBatchform:[],
        uploadImgList:[],
        uploadImgs:[],
        imglist:[],
        formdata:{
          vegetables:'',
          weight:0
        },
        formdata2:{
          vegetables:"",
          vegetablesId:0
        },
        loading:false,
        dialogFormVisible:false,
        dialogFormVisible2:false,
        dialogFormVisible3:false,
        dialogFormVisible4:false,
        editdata:[],
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 1
        },
        option:{
          searchShow: true,
          menuname:"修改",
          searchMenuSpan: 6,
          tip: false,
          tree: true,
          border: true,
          selection: true,
          dataType: 'string',
          viewBtn: false,
          editBtn:false,
          delBtn:false,
          showSummary:true,
          // sumColumnList:[
          //   {
          //     label:"总计:",
          //     name:"cartonNum",
          //     type:"sum"
          //   },
          //   {
          //     label:"总计:",
          //     name:"baggedNum",
          //     type:"sum"
          //   }
          // ],
          column:[
            {
              label:"图片",
              prop:"imgUrl",
              type:"upload",
              listType:"picture-card",
              span:24,
              propsHttp:{
                res: "data",
                url:"imgUrl"
              },
              canvasOption: {
              text: '兄弟',
              ratio: 0.1
              },
              action:"http://localhost:1888/api/blade-system/classfl/uploadImg2"     
            },
            {
                label:"蔬菜类名",
                prop:"vegetables",
                search:true
            },
            {
                label:"净重量(kg)",
                prop:"weight",
                dataType: "number"
            }
          ]
        }
      }
   },
   methods:{
    onLoad(page, params = {}) {
        this.loading = true;
        params["userId"]=this.userId;
        params["roleId"]=this.roleId;
        console.log(params);
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          this.data = res.data.data.data;
          this.page.total=res.data.data.count;
          this.loading = false;
        });
      },
      updatePrice(row){
        console.log(row);
        //查询正在售卖批次\
        var obj = {
           "batchCode" : row.batchCode,
           "vageId":row.vegetablesId
         };
         getBatchDetail(obj).then(res=>{
           console.log(res);
           if(res.data.code==200){
            this.formdata2.vegetables = row.vegetables;
            this.formdata2.vegetablesId = row.vegetablesId;
            this.dialogFormVisible3=true;
            this.editBatch = res.data.data;
            console.log(this.editBatch);
           }else{
              this.$message.error(res.data.msg);
           }
        })
      },
      updateVegeName(){
          console.log(this.formdata2);
          updateVege(this.formdata2).then(res=>{
            if(res.data.code==0){
               this.$message.error(res.data.msg);
           }else{
               this.$message.success("修改成功");
               this.onLoad(this.page,{});
           }
          })
      },
      pushSell(){
        //推送
        if(Object.keys(this.pushdata).length == 0){
          this.$message.error("请选择推送的品类");
          return false;
        }
        this.dialogFormVisible4 = true;
        //查询可以推送的用户
        var obj={
          templateId:1,
          roleId:2
        }
        getuserList(obj).then(res={
            
        })
        console.log(this.pushdata);
      },
      selectionChange(item){
          this.pushdata = item;
          console.log(this.pushdata);
      },
      handleRemoveIcon(file){
          console.log(file);
          var newimgList=[];
          this.uploadImgList.forEach(elem=>{
             if(elem.name!=file.name){
              newimgList.push({
                 "img":elem.img,
                 "name":elem.name
              })
             } 
          })
          this.uploadImgList = newimgList;
      },
      handleAvatarChangeIcon(file,fileList){
        const isJPG = file.raw.type === 'image/jpeg'
	      const isPNG = file.raw.type === 'image/png'
	      const isLt2M = file.raw.size / 1024 / 1024 < 0.5
	      // this.hideUploadIcon = fileList.length >= 1;
	      if (!isPNG && !isJPG) {
	      	this.$message.error('上传图片只能是 JPG/PNG 格式!')
	      	return false
	      }else if ((isPNG || isJPG)) {
          this.uploadImgList.push(file.raw);
	      }
      },
      beforeAvatarUpload(file){
         console.log(file);  
      },
      uploadSectionFile(file){
          console.log(file); 
      },
      handleAvatarSuccess(file){
        console.log(file);
      },
      searchChange(params, done){
          this.page.currentPage = 1;
          this.onLoad(this.page, params);
          done();
      },
      searchReset(){
        this.parentId = 0;
        this.onLoad(this.page);
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize) {
        this.page.pageSize = pageSize;
      },
      rowSave(row){
           row["imglist"]=this.imglist;
           row["userId"]=this.userId;
           var imgurl="";
           this.imglist.forEach(res=>{
            if(imgurl.length==0){
              imgurl +=res;
            }else{
              imgurl+=res+",";
            }
           })
           row["imgUrl"]=imgurl;
           this.loading=false;
           console.log(row);
           addage(Object.assign(row,this.query)).then(res=>{
            this.loading=false;
               if(res.data.code==0){
               this.$message.error(res.data.msg);
           }else{
               this.$message.success("新增成功");
               setTimeout(function(){
                 location.reload();
               },3000);
           }
        })
      },
      Removegoods(row){
        this.$confirm('是否下架该商品').then((status)=>{
          if(status ==  'confirm'){
              if(row.cartonNum>0){
                this.$message.error("无法删除,商品还有余货");
                return false;
              }
              if(row.baggedNum>0){
                this.$message.error("无法删除,商品还有余货");
                return false;
              }
            var formdata=new FormData();
            formdata.append("id",parseInt(row.vegetablesId));
            formdata.append("status",1);
            removegoods(formdata).then(res=>{
              if(res.data.code==0){
               this.$message.error(res.data.msg);
           }else{
               this.$message.success("下架成功");
               this.onLoad(this.page,{});
              //  setTimeout(function(){
              //    location.reload();
              //  },3000);
           }
            })
          }
        });
      },
      uploadAfter (file, done) {
        this.uploadimg=file.imgUrl;
        this.imglist.push(file.imgUrl);
        done();
      },
      uploadDelete(file){
        this.$confirm('是否确认删除，无法撤回').then((status)=>{
          if(status ==  'confirm'){
            this.imglist=this.editdata.imglist.filter(function(item,idx){
                 return item!=file;
            })
            //修改图片数据
            var formdata=new FormData();
            formdata.append("imgList",this.imglist);
            formdata.append("vageId",this.editdata.vegetablesId);
            delimg(formdata).then(res=>{
               if(res.data.code==0){
                this.$message.error(res.data.msg);
               }else if(res.data.code==200){
                this.$message.success("删除成功");
                this.editdata.imglist = this.imglist;
                // setTimeout(function(){
                //      location.reload();
                // },3000);
                }
            })
          }
        });
      },
      handleEdit(row){
        //补货
        this.formdata.vageId=row.vegetablesId;
        this.dialogFormVisible=true; 
        //查询正在售卖批次\
        var obj = {
           "batchCode" : row.batchCode,
           "vageId":row.vegetablesId
         };
         getBatchDetail(obj).then(res=>{
           if(res.data.code==200){
            console.log(res);
            this.editBatch = res.data.data;
           }else{
              this.$message.error(res.data.msg);
           }
        })
      },
      Editdta(row){
         this.dialogFormVisible2=true;
         this.editdata=row;
         this.formdata.vegetables = row.vegetables;
         this.formdata.weight = row.weight;
         this.imglist=row.imglist;
      },
      addimg(){
        //只允许上传5张
        var formdata= new FormData();
        formdata.append("vageId",this.editdata.vegetablesId);
        for(var i=0;i<this.uploadImgList.length;i++){
          if(this.uploadImgList[i].size/1024/1024 > 10){
            this.$message.error("文件大小不能大于10M");
            return false;
          }
          formdata.append("files",this.uploadImgList[i]);
        }
        var count = this.editdata.imglist.length + this.uploadImgList.length;
        if(count>5){
          this.$message.error("只允许上传5张图");
          return false;
        }
        if(this.formdata.vegetables==null || this.formdata.vegetables=='' || this.formdata.vegetables==undefined){
          this.$message.error("請輸入類名");
          return false;
        }
        formdata.append("vegetables",this.formdata.vegetables);
        formdata.append("weight",this.formdata.weight);
        uploadImg(formdata).then(res=>{
           if(res.data.code==0){
            this.$message.error(res.data.msg);
           }else if(res.data.code==200){
            this.uploadImgList=[];
            this.$message.success("添加成功");
            setTimeout(function(){
                 location.reload();
            },3000);
           }
        })
      },
      addRestock(){
        this.formdata["addUserId"]= this.userId;
        this.formdata["roleId"]= this.roleId;
        if(!this.checked1 && !this.checked2){
          this.$message.error("请勾选进货类型");
          return false;
        }
        if(this.checked1){
          if(this.formdata.baggedPrice==0 || this.formdata.baggedWeight==0 || this.formdata.baggedNum==0){
                  this.$message.error("请填写有效数字");
                  return false;
          }
          if(this.formdata.baggedPrice==null || this.formdata.baggedPrice==''){
           this.$message.error("请填写完整");
           return false;
          }
          if(this.formdata.baggedWeight==null || this.formdata.baggedWeight==''){
           this.$message.error("请填写完整");
           return false;
          }
          if(this.formdata.baggedNum==null || this.formdata.baggedNum==''){
           this.$message.error("请填写完整");
           return false;
          }
        }
        if(this.checked2){
          if(this.formdata.cartonPrice==0 || this.formdata.cartonWeight==0 || this.formdata.cartonNum==0){
              this.$message.error("请填写有效数字");
              return false;
          }
          if(this.formdata.cartonPrice==null || this.formdata.cartonPrice==''){
           this.$message.error("请填写完整");
           return false;
          }
          if(this.formdata.cartonWeight==null || this.formdata.cartonWeight==''){
           this.$message.error("请填写完整");
           return false;
          }
          if(this.formdata.cartonNum==null || this.formdata.cartonNum==''){
           this.$message.error("请填写完整");
           return false;
          }
        }
        this.formdata["checked1"]=this.checked1;
        this.formdata["checked2"]=this.checked2;
        if(this.checked1 || this.checked2){
          addRestock(Object.assign(this.formdata, this.query)).then(res=>{
            if(res.data.code==0){
            this.$message.error(res.data.msg);
           }else if(res.data.code==200){
            this.formdata=[];
            this.checked1=false;
            this.checked2=false;
            this.$message.success("添加成功");
            setTimeout(function(){
                 location.reload();
            },3000);
           }
        })
        }
        
    },
    updateVege(index){
      console.log(this.editBatch[index]);
      var update=false;
      //修改基本数据
      if(this.editBatch[index]["sellcartonPrice"]!=undefined && this.editBatch[index]["sellcartonPrice"]!=''){
        if(this.editBatch[index].sellcartonPrice<=0){
           this.$message.error("不能小于0");
           return false;
        }
        update=true;
      }
      if(this.editBatch[index]["sellcartonNum"]!=undefined && this.editBatch[index]["sellcartonNum"]!=''){
        if(this.editBatch[index].sellcartonNum<=0){
           this.$message.error("不能小于0");
           return false;
        }
        update=true;
      }    
      if(this.editBatch[index]["sellcartonWeight"]!=undefined && this.editBatch[index]["sellcartonWeight"]!=''){
        if(this.editBatch[index].sellcartonWeight<=0){
           this.$message.error("不能小于0");
           return false;
        }
        update=true;
      }
      if(this.editBatch[index]["sellbaggedPrice"]!=undefined && this.editBatch[index]["sellbaggedPrice"]!=''){
        if(this.editBatch[index].sellbaggedPrice<=0){
           this.$message.error("不能小于0");
           return false;
        }
        update=true;
      } 
      if(this.editBatch[index]["sellbaggedWeight"]!=undefined && this.editBatch[index]["sellbaggedWeight"]!=''){
        if(this.editBatch[index].sellbaggedWeight<=0){
           this.$message.error("不能小于0");
           return false;
        }
        update=true;
      }  
      if(this.editBatch[index]["sellbaggedNum"]!=undefined && this.editBatch[index]["sellbaggedNum"]!=''){
        if(this.editBatch[index].sellbaggedNum<=0){
           this.$message.error("不能小于0");
           return false;
        }
        update=true;
      }     
      if(update){
        this.editBatch[index]["isSell"] = 1;
      this.editBatch[index]["vegetablesId"]=this.editBatch[index].vageId
      updateVege(this.editBatch[index]).then(res=>{
        if(res.data.code==0){
        this.$message.error(res.data.msg);
       }else if(res.data.code==200){
        this.formdata2=[];
        this.checked3=false;
        this.checked4=false;
        this.$message.success("修改成功");
        setTimeout(function(){
          location.reload();
        },3000);
       }
    })
      }
    },
  addRestockBatch(index){
    var update=false;
      //修改基本数据
      if(this.editBatch[index]["sellcartonPrice"]!=undefined && this.editBatch[index]["sellcartonPrice"]!=''){
        if(this.editBatch[index].sellcartonPrice<=0){
           this.$message.error("不能小于0");
           return false;
        }
      }
      if(this.editBatch[index]["sellcartonNum"]!=undefined && this.editBatch[index]["sellcartonNum"]!=''){
        if(this.editBatch[index].sellcartonNum<=0){
           this.$message.error("不能小于0");
           return false;
        }
        update=true;
      }    
      if(this.editBatch[index]["sellcartonWeight"]!=undefined && this.editBatch[index]["sellcartonWeight"]!=''){
        if(this.editBatch[index].sellcartonWeight<=0){
           this.$message.error("不能小于0");
           return false;
        }
      }
      if(this.editBatch[index]["sellbaggedPrice"]!=undefined && this.editBatch[index]["sellbaggedPrice"]!=''){
        if(this.editBatch[index].sellbaggedPrice<=0){
           this.$message.error("不能小于0");
           return false;
        }
      } 
      if(this.editBatch[index]["sellbaggedWeight"]!=undefined && this.editBatch[index]["sellbaggedWeight"]!=''){
        if(this.editBatch[index].sellbaggedWeight<=0){
           this.$message.error("不能小于0");
           return false;
        }
      }  
      if(this.editBatch[index]["sellbaggedNum"]!=undefined && this.editBatch[index]["sellbaggedNum"]!=''){
        if(this.editBatch[index].sellbaggedNum<=0){
           this.$message.error("不能小于0");
           return false;
        }
        update=true;
      }
      console.log(this.editBatch[index]); 
      this.editBatch[index]["vegetablesId"]=this.editBatch[index].vageId;
      this.editBatch[index]["userId"]=this.userId;
      if(update){
        addRestockBatch(this.editBatch[index]).then(res=>{
            if(res.data.code==200){
              this.$message.success("操作成功");
              this.onLoad(this.page,{});
              this.dialogFormVisible = false;
            }else{
              this.$message.error(res.data.msg);
            }
        })
      }else{
        this.$message.error("至少添加一种");
      }
  }
  }
}

</script>

<style>
.closeimg{
  cursor: pointer;
}
.closeimg:hover{
  color: #F56C6C !important;
}
.avatar-uploader .el-upload {
    border: 1px dashed #8c939d;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100%;
    height: 100%;
    line-height: 150px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>